package com.xinchengxd.goods.service.impl;

import com.xinchengxd.commons.entity.dto.GoodsNums;
import com.xinchengxd.commons.entity.goods.Goods;
import com.xinchengxd.commons.entity.goods.ShoppingCart;
import com.xinchengxd.goods.mapper.GoodsMapper;
import com.xinchengxd.goods.service.GoodsService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 姚新成
 * @Date: 2021/11/9:0:15
 * @Description:
 */

@Service
public class GoodsServiceImpl implements GoodsService {
    @Resource
    GoodsMapper goodsMapper;


    @Override
    public List<Goods> limit(Integer number) {
        List<Goods> gds = goodsMapper.limit(number);
        return gds;
    }

    @Override
    public Goods findById(Integer id) {
        return goodsMapper.findById(id);
    }

    @Override
    public int stock(Integer num,Integer id) {
        Goods byId = goodsMapper.findById(id);
        if(byId == null){
            return 0;
        }
        num += byId.getStock();
        if(num >= 0){
            return goodsMapper.stock(num,id);
        }else{
            return 0;
        }

    }

    @Override
    public List<Goods> findByList(List<GoodsNums> item) {
        return goodsMapper.findByList(item);
    }

    @Override
    public List<ShoppingCart> findCart(Integer userId) {

        return goodsMapper.findCart(userId);
    }
}
